package com.dcm.bargain.controller;

import com.dcm.bargain.client.OrderClient;
import com.dcm.bargain.dto.OrderDto;
import com.dcm.bargain.entity.CutPriceEntity;
import com.dcm.bargain.service.CutPriceService;
import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.common.vo.CommonResponse;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:zhouyuhan 时间: 2021/3/30 17:10
 */
@RestController
@EnableResponseBodyAdvice
@RequestMapping("/cut")
public class CutPriceController {

    @Autowired
    private CutPriceService cutPriceService;

    @Autowired
    private OrderClient orderClient;

    /**
     * 砍价状态开启、关闭
     *
     * @param id
     */
    @ApiOperation("开启、关闭")
    @EnableResponseBodyAdvice
    @PutMapping("/updateStatus")
    public void updateStatus(@RequestParam(value = "id", required = false) Long id) {
        cutPriceService.updateStatus(id);
    }

    /**
     * 查询商品
     *
     * @param id
     * @return
     */
    @ApiOperation("查询商品")
    @EnableResponseBodyAdvice
    @GetMapping("/findOne")
    public CutPriceEntity findCutProduct(@RequestParam(value = "id") Long id) {
        return cutPriceService.findCutProduct(id);
    }

    /**
     * 砍价状态已结束删除
     *
     * @param id
     */
    @ApiOperation("砍价状态已结束删除")
    @EnableResponseBodyAdvice
    @DeleteMapping("/deleteStatus")
    public void deleteStatus(@RequestParam(value = "id", required = false) Long id) {
        cutPriceService.deleteStatus(id);
    }


    /**
     * 查询全部、今天、昨天、近7天、近30天、本月、本年
     *
     * @param currentPage
     * @param pageSize
     * @param whichDay
     * @return
     */
    @ApiOperation("全部、今天、昨天、近7天、近30天、本月、本年")
    @EnableResponseBodyAdvice
    @GetMapping("/findTime")
    public List<CutPriceEntity> findTime(
            @RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize", defaultValue = "2") Integer pageSize,
            @RequestParam(value = "whichDay", required = false) String whichDay) {
        return cutPriceService.findTime(currentPage, pageSize, whichDay);
    }

    /**
     * 发起砍价
     *
     * @param bid 砍价商品id
     * @param uid 用户id
     */
    @ApiOperation("发起砍价")
    @GetMapping("/startBargain")
    public CommonResponse startBargain(@RequestParam(value = "bid", required = false) Long bid,
                                       @RequestParam(value = "uid", required = false) Long uid) {
        return cutPriceService.startBargain(bid, uid);
    }

    @ApiOperation("帮助砍价")
    @GetMapping("/helpBargain")
    public CommonResponse helpBargain(@RequestParam(value = "id", required = false) Long id,
                              @RequestParam(value = "uid", required = false) Long uid) {

        CommonResponse commonResponse = cutPriceService.helpBargain(id, uid);

        return commonResponse;
    }
}
